﻿@using System.Globalization
@inject GlobalConfig GlobalConfig;
@inject I18n I18n
@inject NavigationManager Nav

<MMenu OffsetY Bottom>
    <ActivatorContent>
        <div Color="white" @attributes="@context.Attrs" Class="hover-pointer ml-6 mr-5 neutral-lighten-4--text text-center">
            <MIcon>mdi-google-translate</MIcon>
        </div>
    </ActivatorContent>
    <ChildContent>
        <MList Class="py-0">
            <MListItemGroup ActiveClass="primary" Value="GlobalConfig.Language.Name">
                @foreach (var language in I18n.SupportedCultures)
                {
                    <MListItem OnClick="()=> OnLanguageChange(language)" Value="language.Name">
                        <ItemContent>
                            <MListItemContent>
                                <span class="@(context.Active?"white--text":"neutral-lighten-4--text") text-btn">
                                    @language.NativeName
                                </span>
                            </MListItemContent>
                        </ItemContent>
                    </MListItem>
                }
            </MListItemGroup>
        </MList>
    </ChildContent>
</MMenu>

@code {
    void OnLanguageChange(CultureInfo language)
    {      
        I18n.SetCulture(language);
        GlobalConfig.Language = language;
        Nav.NavigateTo(Nav.Uri,true);
    }
}
